home *** CD-ROM | disk | FTP | other *** search
/ MACup: Giveaway 1996 / Image.iso / Shareware & Demos / Web-Publishing / SNAP PrimeBase / PrimeBase™ Server 68K / Setup / Scripts / setv.dal < prev    next >
Encoding:
Text File  |  1996-07-13  |  2.3 KB  |  95 lines  |  [TEXT/ds30]

  1. declare procedure setv(str, val, which)
  2. argument varchar str = $null;
  3. argument generic val = $null;
  4. argument integer which = $null;
  5. {
  6.     boolean opened_master = $false;
  7.     varchar type, value, string;
  8.     objname var;
  9.     integer i;
  10.     
  11.     describe open databases;
  12.     if ($rowcnt == 0) {
  13.         opened_master = $true;
  14.         open database master;
  15.     }
  16.     
  17.     if (str is null) {
  18.         select a.creatorname, a.name, b.datatype, b.value 
  19.         from   sysobjects a, sysvariables b
  20.         where  a.dbid = b.dbid for extract;
  21.     }
  22.     else {
  23.         select a.creatorname, a.name, b.datatype, b.value 
  24.         from   sysobjects a, sysvariables b
  25.         where  a.name like :str and
  26.                a.dbid = b.dbid for extract;
  27.     }
  28.     if ($rowcnt == 0)
  29.         print "No match found for '"+str+"'.";
  30.     else {
  31.         i = 1;
  32.         for each {
  33.             if (->datatype == $integer)
  34.                 type = "INTEGER";
  35.             else if (->datatype == $smint)
  36.                 type = "SMINT";
  37.             else if (->datatype == $date)
  38.                 type = "DATE";
  39.             else if (->datatype == $timestamp)
  40.                 type = "TIMESTAMP";
  41.             else if (->datatype == $time)
  42.                 type = "TIME";
  43.             else if (->datatype == $date)
  44.                 type = "DATE";
  45.             else if (->datatype == $decimal)
  46.                 type = "DECIMAL";
  47.             else if (->datatype == $boolean)
  48.                 type = "BOOLEAN";
  49.             else
  50.                 type = "";
  51.             if (->value is null)
  52.                 value = "$NULL";
  53.             else
  54.                 execute "value = VARCHAR(" + type + " ->value);";
  55.             if (->datatype == $varchar)
  56.                 string = """" + value + """";
  57.             else
  58.                 string = value;
  59.             string = "SET VARIABLE " + ->creatorname + "." + ->name + " = " + string;
  60.             if (val is not null) {
  61.                 if ($rowcnt == 1 or (which is not null and i == which)) {
  62.                     var = ->creatorname + "." + ->name;
  63.                     if (varchar val == value)
  64.                         string = string + " == ";
  65.                     else {
  66.                         SET VARIABLE var = val;
  67.                         string = string + " -> ";
  68.                     }
  69.                     if (->datatype == $varchar)
  70.                         string = string + """" + varchar val + """";
  71.                     else
  72.                         string = string + varchar val;
  73.                 }
  74.             }
  75.             if ($rowcnt > 1) {
  76.                 string = "(" + varchar i + ") " + string;
  77.                 i++;
  78.             }
  79.             print string + ';';
  80.         }
  81.         if (val is not null) {
  82.             if (which is not null) {
  83.                 if (which <= 0 or which > $rowcnt) 
  84.                     print "Selected value "+varchar which+", is out of range";
  85.             }
  86.             else if ($rowcnt > 1)
  87.                 print "No value set, '"+str+"' is ambiguous.";
  88.         }
  89.     }
  90.  
  91.     if (opened_master)
  92.         close database master;
  93. }
  94. end procedure setv;
  95.